//
//  WConst.swift
//  iiatn
//
//  Created by mnine on 18/3/28.
//  Copyright © 2018年 mnine. All rights reserved.
//

import UIKit

let notifyNameMsgRecv = NSNotification.Name(rawValue:"notifyNameMsgRecv")

var wlogan: Bool? = false      // 是否成功登录过？ 如果说true那么直接用数据库保留的，直接登录
var whaslogin: Bool? = false   // 是否是登录状态
var wuserid: Int? = nil            // 用户id
var wname: String? = nil           // 用户名
var wphone: String? = nil           // 用户电话
var wemail: String? = nil           // 用户邮箱
var wcompany_name: String? = nil    // 用户公司
var wprovince: String? = nil        // 用户电话
var wcity: String? = nil            // 用户电话
var waddress: String? = nil         // 用户地址

enum WTopicType: Int {
    /// 精选
    case Selection = 4
    /// 美食
    case Food = 14
    /// 家居
    case Household = 16
    /// 数码
    case Digital = 17
    /// 美物
    case GoodThing = 13
    /// 杂货
    case Grocery = 22
}

enum WShareButtonType: Int {
    /// 微信朋友圈
    case WeChatTimeline = 0
    /// 微信好友
    case WeChatSession = 1
    /// 微博
    case Weibo = 2
    /// QQ 空间
    case QZone = 3
    /// QQ 好友
    case QQFriends = 4
    /// 复制链接
    case CopyLink = 5
}

enum WOtherLoginButtonType: Int {
    /// 微博
    case weiboLogin = 100
    /// 微信
    case weChatLogin = 101
    /// QQ
    case QQLogin = 102
}

/// 服务器地址
let BASE_URL = "http://www.china-ofdi.org/"

/// 第一次启动
let WFirstLaunch = "firstLaunch"
/// 是否登录
let isLogin = "isLogin"

/// code 码 1 操作成功
let RETURN_OK = 1
/// 间距
let kMargin: CGFloat = 10.0
/// 圆角
let kCornerRadius: CGFloat = 5.0
/// 线宽
let klineWidth: CGFloat = 1.0
/// 首页顶部标签指示条的高度
let kIndicatorViewH: CGFloat = 2.0
/// 新特性界面图片数量
let kNewFeatureCount = 4
/// 顶部标题的高度
let kTitlesViewH: CGFloat = 45
/// 顶部标题的y
let kTitlesViewY: CGFloat = 64
/// 动画时长
let kAnimationDuration = 0.25
/// 屏幕的宽
let SCREENW = UIScreen.main.bounds.size.width
/// 屏幕的高
let SCREENH = UIScreen.main.bounds.size.height
/// 分类界面 顶部 item 的高
let kitemH: CGFloat = 100
/// 分类界面 顶部 item 的宽
let kitemW: CGFloat = 150
/// 我的界面头部图像的高度
let kYMMineHeaderImageHeight: CGFloat = 200
/// 分享按钮背景高度
let kTopViewH: CGFloat = 230

/// RGBA的颜色设置
func WColor(r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> UIColor {
    return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a)
}
/// 背景白色略显
func WLightWhiteColor() -> UIColor {
    return WColor(r: 250, g: 250, b: 250, a: 1)
}
/// 深红
func WRedColor() -> UIColor {
    return WColor(r: 196, g: 0, b: 100, a: 1)
}
/// 背景灰色
func WGlobalColor() -> UIColor {
    return WColor(r: 240, g: 240, b: 240, a: 1)
}
func WGlobalWhiteColor() -> UIColor {
    return WColor(r: 250, g: 250, b: 250, a: 1)
}
//浅灰色
func WlightGrayColor() -> UIColor {
    return WColor(r: 240, g: 240, b: 240, a: 0.25)
}

//浅浅灰色
func WllightGrayColor() -> UIColor {
    return WColor(r: 153, g: 153, b: 153, a: 1)
}

//浅绿色
func WlightGreenColor() -> UIColor {
    return WColor(r: 0, g: 204, b: 74, a: 0.8)
}

/// 红色
func WGlobalRedColor() -> UIColor {
    return WColor(r: 245, g: 80, b: 83, a: 1.0)
}

/// iPhone 5
let isIPhone5 = SCREENH == 568 ? true : false
/// iPhone 6
let isIPhone6 = SCREENH == 667 ? true : false
/// iPhone 6P
let isIPhone6P = SCREENH == 736 ? true : false

enum Validate {
    case email(_: String)
    case phoneNum(_: String)
    case carNum(_: String)
    case username(_: String)
    case password(_: String)
    case nickname(_: String)
    
    case URL(_: String)
    case IP(_: String)
    
    
    var isRight: Bool {
        var predicateStr:String!
        var currObject:String!
        switch self {
        case let .email(str):
            predicateStr = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"
            currObject = str
        case let .phoneNum(str):
            // predicateStr = "^((13[0-9])|(15[^4,\\D]) |(17[0,0-9])|(18[0,0-9]))\\d{8}$"
            predicateStr = "^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$"
            currObject = str
        case let .carNum(str):
            predicateStr = "^[A-Za-z]{1}[A-Za-z_0-9]{5}$"
            currObject = str
        case let .username(str):
            predicateStr = "^[A-Za-z0-9]{6,20}+$"
            currObject = str
        case let .password(str):
            predicateStr = "^[a-zA-Z0-9]{6,20}+$"
            currObject = str
        case let .nickname(str):
            predicateStr = "^[\\u4e00-\\u9fa5]{4,8}$"
            currObject = str
        case let .URL(str):
            predicateStr = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$"
            currObject = str
        case let .IP(str):
            predicateStr = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
            currObject = str
        }
        
        let predicate =  NSPredicate(format: "SELF MATCHES %@" ,predicateStr)
        return predicate.evaluate(with: currObject)
    }
}
